import send_msg from '@feidao-factory/send-msg';

export interface IUserInfo {
	_id: string;
	usercode: string;
	user_name: string;
	name_spell: string;
	is_disabled: boolean;
	create_time: number;
	productid: string;
	avatar_path: string;
	avatar_name: string;
	avatar_type: string;
	email: string;
	phone: string;
	last_login_time: number;
	phone_verified: boolean;
	email_verified: boolean;
	is_admin: boolean;
	code: number;
	msg: string;
	sessionID: string;
}

/**
 * 用户登录
 * @param action_id 系统参数action_id
 * @param session_id 系统参数session_id
 * @param spaceid 系统参数sapceid
 * @param usr 用户名
 * @param psw 密码
 * @example user_login(action_id, session_id, spaceid, usr, psw);
 */
export default async function user_login(action_id: string, session_id: string, spaceid: string, usr: string, psw: string) {
	const msg = {
		logintypenew: 'usercode',
		spaceid,
		usercode: usr,
		userpw: psw
	};

	return send_msg<IUserInfo>(action_id, session_id, 'loginservice.userlogin', msg);
}
